<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Bootstrap 实例</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<script type="text/javascript" src="libs/bootstrap/js/jquery-3.1.1.js"></script>
		<script type="text/javascript" src="libs/bootstrap/js/bootstrap.js"></script>
		<link rel="stylesheet" href="libs/bootstrap/css/bootstrap.css" />

		<style>
			ul {
				top: 20px;
				position: fixed;
			}
			
			div.col-sm-9 section {
				height: 250px;
				font-size: 28px;
			}
			
			#section1 {
				color: #fff;
				background-color: #1E88E5;
			}
			
			#section2 {
				color: #fff;
				background-color: #673ab7;
			}
			
			#section3 {
				color: #fff;
				background-color: #ff9800;
			}
			
			#section41 {
				color: #fff;
				background-color: #00bcd4;
			}
			
			#section42 {
				color: #fff;
				background-color: #009688;
			}
			
			@media screen and (max-width: 810px) {
				#section1,
				#section2,
				#section3,
				#section41,
				#section42 {
					margin-left: 150px;
				}
			}
		</style>
	</head>
	<!--重点：data-spy="scroll" 一定 写在要监听的滚动实体上，通常是body
	data-target="#myScrollspy" 是当滚动时要触发哪个元素的事件，比如导航栏：<nav class="col-sm-3" id="myScrollspy">
<!--重点<li><a href="#section2">Section 2</a></li>-->
	<!--和这个的id一样-->
	<!--<div id="section1">    
				<h1>Section 1</h1>
				<p>Try to scroll this section and look at the navigation list while scrolling!</p>
	</div>-->
	<!--导航的样式改变是根据active这个样式来的，所以要写这个样式-->

	<!---->-->
	<!--重点：data-spy="scroll" 一定 写在要监听的滚动实体上，通常是body-->

	<body data-spy="scroll" data-target="#myScrollspy" data-offset="20">


			<div class="row">

				<!--data-target="#myScrollspy" 是当滚动时要触发哪个元素的事件，比如导航栏：<nav class="col-sm-3" id="myScrollspy">-->
				<div id="myScrollspy">
					<div>
						<div>
							<!--这个 nav 必须要，内部.nav li >  nav-pills可以换成其中哪个？但也必须要 a-->
							<ul class="nav nav-pills nav-stacked">
								<li class="active">
									<a href="#section1">Section 1</a>
								</li>
								<!--重点<li><a href="#section2">Section 2</a></li>-->
								<li>
									<a href="#section2">Section 2</a>
								</li>
								<li>
									<a href="#section3">Section 3</a>
								</li>

							</ul>
						</div>
					</div>
				</div>
				<div class="col-sm-9">
					<section id="section1">
						<h1>Section 1</h1>
						<p>Try to scroll this section and look at the navigation list while scrolling!</p>
					</section>
					<section id="section2">
						<h1>Section 2</h1>
						<p>Try to scroll this section and look at the navigation list while scrolling!</p>
					</section>
					<section id="section3">
						<h1>Section 3</h1>
						<p>Try to scroll this section and look at the navigation list while scrolling!</p>
					</section>
					<section id="section41">
						<h1>Section 4-1</h1>
						<p>Try to scroll this section and look at the navigation list while scrolling!</p>
					</section>
					<div id="section42">
						<h1>Section 4-2</h1>
						<p>Try to scroll this section and look at the navigation list while scrolling!</p>
					</div>
				</div>
			</div>
		

	</body>

</html>
<script type="text/javascript">
	$('#myScrollspy').on('activate.bs.scrollspy', function() {

		//		  alert('触发新的楼层了');
		console.log('滚动了');
	});
	$(window).scroll(function() {
		//			console.log('body滚动了');
	});
</script>